package threading;

class Counter1 {
    private int count = 0;

    synchronized public void add() {
         count++;
    }

    public int getCount() {
        return count;
    }
}
public class ThreadDemo28 {
    public static void main(String[] args) throws InterruptedException {
        Counter1 counter1 = new Counter1();
        Object object = new Object();
        Thread t1 = new Thread( () -> {
            for (int i = 0; i < 50000; i++) {

                    counter1.add();

            }
        });
        Thread t2 = new Thread( () -> {
            for (int i = 0; i < 50000; i++) {

                    counter1.add();

            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(counter1.getCount());
    }
}
